function t(t) {
    return t.substring(1);
}

wx.getSystemInfoSync().windowWidth;

var o = getApp();

Page({
    data: {
        textConfig: {
            text: "",
            color: "#000000",
            size: 45,
            font: 0
        },
        bgConfig: {
            height: 300,
            width: 700,
            color: ""
        },
        bgColorArray: [ "透明背景", "微信默认背景颜色", "QQ默认背景颜色", "白色", "黑色" ],
        bgObColorArray: [ "", "#EDEDED", "#EAEDF4", "#ffffff", "#000000" ],
        fontColorArray: [ "黑色", "白色", "红色", "橙色", "黄色", "绿色", "蓝色", "靛色", "紫色" ],
        fontVaColorArray: [ "#000000", "#ffffff", "#FF0000", "#FF7D00", "#FFFF00", "#00FF00", "#0000FF", "#00FFFF", "#FF00FF" ],
        fontList: [ "思源黑体", "思源宋体", "手写体", "软笔手写", "站酷高端黑", "站酷庆科黄油", "站酷文艺", "站酷小薇logo" ],
        ad: {}
    },
    onShow(){
        this.setData({
            ad: ''
        });
        this.setData({
            ad: getApp().globalData.selfAd[parseInt(getApp().globalData.selfAd.length*Math.random())]
        });
    },
    onLoad: function(t) {
        
    },
    bindBgPickerChange: function(t) {
        var o = this;
        this.setData({
            "bgConfig.color": o.data.bgObColorArray[t.detail.value]
        });
    },
    async textToPic () {
        var a = this.data.textConfig, n = this.data.bgConfig;
        let checkdata = await getApp().checkMsg(a.text)
        console.log(checkdata)
        if(!checkdata||checkdata.result.errCode!==0){
            wx.showModal({
            confirmText: '确定',
            content: '输入内容含有敏感词，请重新输入',
            showCancel: false
            })
            return
        }

        "" == a.text ? wx.showModal({
            title: "提示",
            content: "请输入文字",
            showCancel: !1
        }) : (wx.showLoading({
            title: "检测文本"
        }), wx.request({
            url: o.globalData.apiUrl + "/checkText",
            data: {
                text: a.text
            },
            success: function(e) {
                if (wx.hideLoading(), e.data.success) {
                    wx.showToast({
                        title: "检查通过"
                    }), wx.showLoading({
                        title: "生成图片"
                    });
                    var i = o.globalData.apiUrl + "/api";
                    wx.downloadFile({
                        url: i + "?text=" + a.text + "&font=" + a.font + "&bgColor=" + t(n.color) + "&textColor=" + t(a.color),
                        success: function(t) {
                            wx.hideLoading(), 200 == t.statusCode ? wx.navigateTo({
                                url: "/pages/preview/preview?imageurl=" + t.tempFilePath
                            }) : wx.showToast({
                                title: "服务器出错，请稍候再试",
                                icon: "none"
                            });
                        },
                        fail: function() {
                            wx.showToast({
                                title: "连接出错",
                                icon: "none"
                            });
                        }
                    });
                } else wx.showToast({
                    title: e.data.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                wx.hideLoading(), wx.showToast({
                    title: "连接出错",
                    icon: "none"
                });
            }
        }));
    },
    copyAppName: function() {
        wx.setClipboardData({
            data: "http://textemoji.ishare20.net/",
            success: function(t) {
                wx.showToast({
                    title: "已复制下载地址"
                });
            }
        });
    },
    inputText: function(t) {
        console.log(this.data.textConfig.text), this.setData({
            "textConfig.text": t.detail.value
        });
    },
    bindFontCoPickerChange: function(t) {
        var o = this;
        this.setData({
            "textConfig.color": o.data.fontVaColorArray[t.detail.value]
        });
    },
    bindFontPickerChange: function(t) {
        this.setData({
            "textConfig.font": t.detail.value
        });
    },
    onReady: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        return {
            title: "文字表情制作",
            path: "pages/textmaker/textmaker"
        };
    }
});